<!DOCTYPE stack PUBLIC "-//Apple, Inc.//DTD stack V 2.0//EN" "" >
<stack>
<name>in</name>
<id>-1</id>
<cardCount>1</cardCount>
<cardID>3033</cardID>
<listID>2284</listID>
<cantModify><false /></cantModify>
<cantDelete><false /></cantDelete>
<cantAbort><false /></cantAbort>
<cardSize>
<width>512</width>
<height>342</height>
</cardSize>
<script>-- "Practical Astronomy With Your Calculator" by Peter Duffett-Smith-- (Third Edition) is the book that was used to derive the-- sunrise/sunset calculations.-- Page numbers and paragraph numbers are given for each function.---- sunRiseSet(1986, 3, 10, 42.37, 71.05) This was used to check results.----------------------------------------------------------------------on openStackput the date into field "Date"pass openStackend openStackon closeStackput empty into field "SunRise"put empty into field "SunSet"pass closeStackend closeStack----------------------------------------------------------------------function julianDate year, month, day -- page 7 (#4)set numberFormat to "00.000000000"if month = 1 or month =2 thensubtract 1 from yearadd 12 to monthend ifput int(year/100) into Aput (2-A + int(A/4)) into Bput int(365.25 * year) into Cput int(30.6001 * (month + 1)) into Dput (B+C+D+day+1720994.5) into JDreturn JDend julianDatefunction greenwichSiderealTime Longi, LST -- p.21 (#15)set numberFormat to "00.000000000"put abs(Longi/15) into temp1if Longi >0 thenput (temp1 + LST) into temp1 -- a longitude of West is assumed. Use - for Eastelse put (LST - temp1) into temp1if (temp1 > 24) then put (temp1 -24) into temp1if (temp1 < 0) then put (temp1 + 24) into temp1return temp1end greenwichSiderealTimefunction sunAscDec year, month, day, L -- page.40 (#27)set numberFormat to "00.000000000"put zero into Bput degreesToRadians(23.441884) into ERput degreesToRadians(L) into LRput degreesToRadians(B) into BRput (sin(ER)*sin(LR)*Cos(BR) + sin(BR)*cos(ER)) into Dput asin(D) into Dput radiansToDegrees(D) into Dput (sin(LR)*cos(ER) - tan(BR)*sin(ER)) into yput cos(LR) into xput atan2(y,x) into aput radiansToDegrees(a)/15 into aif a contains "-" then add 24 to areturn a &space &"," &space &Dend sunAscDecfunction siderealTime Lat, al, de -- p.53 (#33)-- Lat = Latitude, phi-- al = Right Ascension, alpha-- de = Declination, deltaset numberFormat to "00.000000000"put degreesToRadians(Lat) into LatTempput degreesToRadians(de) into deTempput (- tan(LatTemp)*tan(deTemp)) into tempput (0.066667)*(acos(temp)) into Hput RadiansToDegrees(H) into Hput (24+al-H) into LSTrif (LSTr > 24) then put (LSTr - 24) into LSTrput (al+H) into LSTsif (LSTs > 24) then put (LSTs - 24) into LSTsreturn (LSTr &space &"," &space &LSTs)end siderealTimefunction deltaTime Lat, de -- p.55 (#33)put degreesToRadians(Lat) into LatTempput degreesToRadians(de) into deTempput ((sin(LatTemp))/(cos(deTemp))) into tempput (acos(temp)) into psiput degreesToRadians(0.830725) into x -- x is a constantput sin(x)/sin(psi) into temp2put asin(temp2) into yput radiansToDegrees(y) into yput (240*y)/cos(deTemp) into dtput dt/3600 into dt -- converted to hoursreturn (dt)end deltaTimefunction sunEclipticLong year, month, day -- page 88 (#46)set numberFormat to "00.000000000"put (julianDate (year, month, day) - 2447891.5) into D -- 2447891.5 is the Julian date for Jan0.0, 1990 (from page 86)put (360*D/365.242191) into Nrepeat until N≤ 360put (N - 360) into Nend repeatrepeat until N≥0put (N + 360) into Nend repeatput T1(year, month, day) into Tput (N + 279.403303 - 282.768442) into M -- constants are from p.87if M contains "-" then add 360 to Mput degreesToRadians(M) into M-- Routine R2, p.90-- solve Kepler's equation by Newton's methodput (10^-6) into epsilonput (epsilon +1) into deltaput M into Erepeat until abs(delta) < (epsilon)put (E - 0.016713*sin(E) - M) into deltaput (delta/(1 - 0.016713*cos(E))) into deltaEput (E - deltaE) into Eend repeatput sqrt((1 + 0.016713)/(1 - 0.016713)) into temp1put (2*atan2(temp1 * tan(E/2), 1)) into knu -- p.89-91put (RadiansToDegrees(knu) + 282.768422) into Lif L > 360 then subtract 360 from Lif L < 0 then add 360 to Lreturn Lend sunEclipticLongfunction T1 year, month, dayset numberFormat to "00.000000000"put ((julianDate (year, month, day) - 2415020.0)/36525.0) into tempreturn tempend T1function sunRiseSet year, month, day, Lat, Longi -- p.95 (#49)set numberFormat to "00.000000000"put sunEclipticLong(year, month, day) into L1put (0.985647 + L1) into L2put sunAscDec(year, month, day, L1) into temp1put sunAscDec(year, month, day, L2) into temp2put (item 1 of temp1) into a1put (item 2 of temp1) into d1put (item 1 of temp2) into a2put (item 2 of temp2) into d2put SiderealTime(Lat, a1, d1) into temp3put SiderealTime(Lat, a2, d2) into temp4put (item 1 of temp3) into LST1rput (item 2 of temp3) into LST1sput (item 1 of temp4) into LST2rput (item 2 of temp4) into LST2sput GreenwichSiderealTime(Longi, LST1r) into GST1rput GreenwichSiderealTime(Longi, LST1s) into GST1sput GreenwichSiderealTime(Longi, LST2r) into GST2rput GreenwichSiderealTime(Longi, LST2s) into GST2sput UtToGst(year, month, day) into T00put (T00 - (- Longi/15)*1.002738) into T00p -- T00p is coming out lowif T00p<0 then put (T00p + 24) into T00pif GST1r<T00p thenput (GST1r + 24) into GST1rput (GST2r + 24) into GST2rend ifif GST1s<T00p thenput (GST1s + 24) into GST1sput (GST2s + 24) into GST2send ifput (interpolation(GST1r, GST2r, T00)) into GSTrput (interpolation(GST1s, GST2s, T00)) into GSTsput (d1 +d2)/2 into dprimeput deltaTime(Lat, dprime) into dtput (GSTs + dt) into GSTsput (GSTr - dt) into GSTrput (gstToUt(year, month, day, GSTr)) into UTrput (gstToUt(year, month, day, GSTs)) into UTsput (utToLocalTime(UTr)) into PSTrput (utToLocalTime(UTs)) into PSTsdelete char 3 to 12 of PSTrdelete char 6 to 15 of PSTrdelete char 3 to 12 of PSTsdelete char 6 to 15 of PSTsreturn (PSTr) &"," &(PSTs)end sunRiseSetfunction UtToGst year, month, day -- p.17 (#12) with Ut=0 (step 5. p.95)set numberFormat to "00.000000000"put (julianDate(year, month, day) - 2451545.0) into Sput S/36525.0 into Tput T0(T) into tempif temp < 0 thenrepeat until temp≥0put (temp + 24) into tempend repeatelse if temp > 24 thenrepeat until temp≤24put (temp - 24) into tempend repeatend ifput temp into GSTreturn GSTend UtToGstfunction T0 T -- p.17 (#12)set numberFormat to "00.000000000"put (6.697374558 + 2400.051336*T + 0.000025862*T*T) into tempreturn tempend T0function interpolation Time1, Time2, T00 --step 8, p.95set numberFormat to "00.000000000"put ((24.07*Time1 - T00*(Time2 - Time1))/(24.07 + Time1 - Time2)) into tempreturn tempend interpolationfunction gstToUt year, month, day, GST -- p.18 (#13)set numberFormat to "00.000000000"put (julianDate(year, month, day) - 2451545.0) into Sput S/36525.0 into Tput T0(T) into tempif temp < 0 thenrepeat until temp≥0put (temp + 24) into tempend repeatelse if temp > 24 thenrepeat until temp≤24put (temp - 24) into tempend repeatend ifput (GST - temp) into temp2if temp2 < 0 thenrepeat until temp2≥0put (temp2 + 24) into temp2end repeatelse if temp2 > 24 thenrepeat until temp2≤24put (temp2 - 24) into temp2end repeatend ifput (temp2*0.9972695663) into utreturn utend gstToUtfunction utToLocalTime UT -- p.15 (#10)global TZoneput (UT + TZone) into temp -- •••••Put proper Time Zoneif temp > 24 then put (temp - 24) into tempif temp < 0 then put (temp + 24) into tempput (temp div 1) into hour -- p.11 (#8)put (temp mod 1) into fractionput (fraction*60) into temp2put (temp2 div 1) into minutesreturn hour &":" &minutesend utToLocalTime-----------------------------------------------------------------------function asin xset numberFormat to "00.000000000"put sqrt(1.0 - x*x) into tempif temp < (1*10^-10) then put (1*10^-10) into tempput atan(x/temp) into temp2return temp2end asinfunction acos xset numberFormat to "00.000000000"put (1.57079632 - asin(x)) into tempreturn tempend acosfunction atan2 y, x -- puts it in the correct quadrant p.40, 41set numberFormat to "00.000000000"put atan(y/x) into tempif x < 0 then put (temp + pi) into tempreturn tempend atan2function degreesToRadians xset numberFormat to "00.000000000"put (x*0.01745329252) into tempreturn tempend degreesToRadiansfunction RadiansToDegrees xset numberFormat to "00.000000000"put (x*57.29577951) into tempreturn tempend RadiansToDegreesfunction int value -- gives integer, the number before the decimal pointreturn (value div 1)end int</script>